//  https://leetcode.cn/problems/teemo-attacking/
// Created by ade on 2022/8/8.
//
#include <iostream>
#include <vector>

using namespace std;

class Solution {
public:
    // 暴力法
    int findPoisonedDuration1(vector<int> &timeSeries, int duration) {
        int len = timeSeries.size();
//        if (len <= 1) return duration;
        int start = timeSeries[0];
        int sum = 0;
        for (int i = 1; i < len; i++) {
            sum += min(duration, timeSeries[i] - start);
//            if (start + duration <= timeSeries[i]) {
//                sum += duration;
//            } else {
//                sum += timeSeries[i] - start;
//            }
            start = timeSeries[i];
        }
        sum += duration;
        return sum;
    }

    int findPoisonedDuration(vector<int> &timeSeries, int duration) {
        int len = timeSeries.size();
        return min(timeSeries[len - 1] - timeSeries[0] + duration, duration * len);

        int sum = 0;
        if (timeSeries[len - 1] - timeSeries[0] >= (len - 1) * duration) {
            sum = duration * len;
        } else {
            sum = timeSeries[len - 1] - timeSeries[0] + duration;
        }
        return sum;
    }
};

int main() {
    Solution so;
    vector<int> times = {1, 2};
    int duration = 2;
    cout << so.findPoisonedDuration(times, duration);
    return 0;
}